package com.powernode.commons.utils;

import com.powernode.commons.constants.Constant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("响应的数据对象")
public class ResponseData {
    @ApiModelProperty("状态码")
    private Integer code= Constant.SUCCESS_CODE;
    @ApiModelProperty("响应的消息")
    private String msg=Constant.SUCCESS_MSG;
    @ApiModelProperty("响应的数据")
    private Object result;
    @ApiModelProperty("数据的总条数")
    private Long count;

    public static ResponseData ok(){
        return new ResponseData();
    }

    public static ResponseData ok(Object data){
        ResponseData responseData = new ResponseData();
        responseData.setResult(data);
        return responseData;
    }
    public static ResponseData ok(String msg,Object data){
        ResponseData responseData = new ResponseData();
        responseData.setResult(data);
        responseData.setMsg(msg);
        return responseData;
    }
    public static ResponseData ok(Object data,Long count){
        ResponseData responseData = new ResponseData();
        responseData.setResult(data);
        responseData.setCount(count);
        return responseData;
    }
    public static ResponseData ok(String msg){
        ResponseData responseData = new ResponseData();
        responseData.setMsg(msg);
        return responseData;
    }

    public static ResponseData error(){
        ResponseData responseData=new ResponseData();
        responseData.setCode(Constant.ERROR_CODE);
        responseData.setMsg(Constant.ERROR_MSG);
        return responseData;
    }

    public static ResponseData error(String msg){
        ResponseData responseData=new ResponseData();
        responseData.setCode(Constant.ERROR_CODE);
        responseData.setMsg(msg);
        return responseData;
    }
}
